package com.liyuhan.onlinetaxibackground.Controller;

import com.liyuhan.onlinetaxibackground.Service.OrderService;
import com.liyuhan.onlinetaxibackground.dto.DataResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping("/doOrder")
    public DataResponse doOrder(@Valid @RequestBody String request) {
        // 用户下单
        return orderService.doOrder(request);
    }

    @RequestMapping("/getOrderState")
    public DataResponse getOrderState(@Valid @RequestBody String request) {
        // 根据订单id订单状态
        return orderService.getOrderState(request);
    }

    @RequestMapping("/cancelOrder")
    public void cancelOrder(@Valid @RequestBody String request) {
        // 根据订单id取消订单
        orderService.cancelOrder(request);
    }

    @RequestMapping("/getOrderList")
    public DataResponse getOrderList(@Valid @RequestBody String request) {
        // 根据用户手机号获取全部订单信息
        return orderService.getOrderList(request);
    }

    @RequestMapping("/getBestOrder")
    public DataResponse getBestOrder(@Valid @RequestBody String request) {
        // 根据司机位置和订单起点位置获取最合适的订单进行派发
        return orderService.getBestOrder(request);
    }

    @RequestMapping("/changeBestOrder")
    public DataResponse changeBestOrder(@Valid @RequestBody String request) {
        // 根据订单id将订单放入司机黑名单，不会再出现订单
        return orderService.changeBestOrder(request);
    }

    @RequestMapping("/deleteOrder")
    public void deleteOrder(@Valid @RequestBody String request) {
        // 根据订单id取消订单
        orderService.deleteOrder(request);
    }

    @RequestMapping("/receiveOrder")
    public DataResponse receiveOrder(@Valid @RequestBody String request) {
        // 根据订单id和司机手机号来绑定 -》 司机+订单+用户
        return orderService.receiveOrder(request);
    }

    @RequestMapping("/getCurrentOrder")
    public DataResponse getCurrentOrder(@Valid @RequestBody String request) {
        // 根据订单id和司机手机号来绑定 -》 司机+订单+用户
        return orderService.getCurrentOrder(request);
    }
}
